/**
 * @author williamJM
 * date 2018/05/10 10:22
 */

"use strict";

define(["app","config/pathConfig"],function (app, pathConfig) {
    app.registerController("ctrl.lock",function ($scope,$http,$state) {

        $scope.password = "";
        $scope.loginMsg = "";
        //获取用户登录的信息
        $scope.user = JSON.parse(sessionStorage.getItem("currentUserInfo"));
        $scope.loginUserInfo = $scope.user.info.authc.credentials;
        $scope.loginUserInfo.pic = pathConfig.backstagePath.getUploadPath() + $scope.loginUserInfo.pic;

        $scope.login = function () {
            if($scope.password === ""){
                $scope.loginMsg = "密码不能为空！";
                return;
            }
            $http.post(pathConfig.backstagePath.getPath() + "/user/password",$scope.password)
                .then(function successCallback(response) {
                    if(response.data.data === true) {
                        $state.go("index.home");
                        sessionStorage.removeItem("locked");
                    } else {
                        $scope.loginMsg = "密码错误，请重新输入！";
                    }
                },function errorCallback(response) {
                    $scope.loginMsg = "服务器错误，请稍后重试！";
                })
        };

        $(document).on("keypress",function (e) {
            if(e.keyCode === 13) {
                $scope.login();
            }
        })


    });
});